﻿<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>吧列表</title>
<link rel="stylesheet" type="text/css" href="<s:property value="staticsRoot"/>/css/style.css"/>
<script type="text/javascript" src="<s:property value="staticsRoot"/>/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
	    $(".data tr:odd").css("background","#fff");
	});
	function doThreadOper(threadId, action, flag){
		if(action == 3 && flag == 1){
			if(!confirm('你确定需要删除帖子吗?')){
				return;
			}
		}
	
		var url;
		if(action == 0){
			url = "../ajaxStickyThread.html";
		}else if(action == 1){
			url = "../ajaxDigestThread.html";
		}else if(action == 2){
			url = "../ajaxLockThread.html";
		}else if(action == 3){
			url = "../ajaxDeleteThread.html";
		}else{
			return;
		}		
		if(flag != 0 && flag != 1){
			return;
		}		
		$.getJSON(url, {"threadId":threadId, "flag":flag}, function(result)	{
			if ($.trim(result.isSuccess)=="1"){
				//刷新当前页面				
				alert("操作成功！");
				window.location.reload();
			}else{
				alert("操作失败，" + result.error);
			}
		}, "json");
	}
	
	function batchDelete(){
		if(isHaveCheck()){
			if(confirm('你确定需要将所选的帖子删除吗?')){
				var threadIds = getCheckedThreadIds();
				$.getJSON("../ajaxBatchDeleteThread.html", $.param({"threadIds":threadIds},true), function(result){
					if ($.trim(result.isSuccess)=="1"){
			 			//刷新当前页面	
						alert("操作成功！");
						window.location.reload();
			 		}else{
			 			alert("操作失败，" + result.error);
			 		}
				}, "json");
			}
		}else{
			alert("请选选择需要删除的帖子");
		}	 	
	}
	
	function query(){
		$("#form1").submit();
	}	
	function doSearch(pageNumber){
		if(pageNumber <= 0){
			pageNumber = 1;
		}	
		$("#page").val(pageNumber); 
		$("#form1").submit(); 
	}
	
</script>
</head>
<body id="user_mag">
<div class="right">
	<h3 class="title box">
    	当前位置：k吧后台管理&nbsp;&gt;&gt;&nbsp;帖子管理&nbsp;&gt;&gt;&nbsp;列表
    </h3>
    <form name="form1" id="form1" action="threadList.html" method="post">
    <table cellpadding="0" cellspacing="0" width="100%" class="table_top box">
    	<tr>
        	<td width="20%" height="50" align="left">
            	吧名称:<input type="text" name="queryDO.barName" class="i_text" value="<s:property value="queryDO.barName"/>"/>
            </td>
            <td width="25%" height="50" align="left">
            	帖子标题:<input type="text" name="queryDO.title" class="i_text"  value="<s:property value="queryDO.title"/>"/>
            </td>
            <td width="30%" height="50" align="left">
            	<input type="checkbox" name="queryDO.sticky" value="1">置顶&nbsp;&nbsp;&nbsp;<input type="checkbox" name="queryDO.digest" value="1">精华&nbsp;&nbsp;&nbsp;<input type="checkbox" name="queryDO.deleted" value="1">已删除&nbsp;&nbsp;&nbsp;<input type="checkbox" name="queryDO.status" value="1">已锁定&nbsp;&nbsp;&nbsp;
            </td>
            <td align="left" style="padding-left:10px;">
            	<div class="lit_btn">
                   <a href="#" onclick="query()">查&nbsp;询</a> 
                </div>
            </td>
        </tr>
        <tr>
        	<td colspan="4" align="left">
        		<div class="lit_btn">
                   <a href="#" onclick="batchDelete();">批量删除</a> 
                </div>
        	</td>
        </tr>
    </table>
    <table cellpadding="0" cellspacing="0" width="100%" class="data">
    	<tr>
    		<th width="3%" align="center"><input type="checkbox" id="checkall" onclick="javascript:checkAll();"/></th>
            <td width="10%" align="center">吧名</td>
            <td width="20%" align="center">帖子标题</td>
            <td width="8%" align="center">置顶</td>
            <td width="8%" align="center">精华</td>
            <td width="8%" align="center">已删除</td>            
            <td width="8%" align="center">已锁定</td>
            <td width="8%" align="center">发表时间</td>
            <td width="8%" align="center">修改时间</td>
            <td align="center" >操作</td>
        </tr> 
        <s:iterator value="threadList" status="status" id="thread">
        <tr>
        	<td align="center"><input type="checkbox" name="threadIds" value="<s:property value="#thread.id"/>"/></td>
            <td align="left"><s:property value="#thread.barName"/></td>
            <td align="left"><s:property value="shortString(#thread.title,15)"/></td>
            <td align="center"><s:if test="#thread.sticky == 1">是</s:if><s:else>否</s:else></td>
            <td align="center"><s:if test="#thread.digest == 1">是</s:if><s:else>否</s:else></td>
            <td align="center"><s:if test="#thread.deleted == 1">是</s:if><s:else>否</s:else></td>            
            <td align="center"><s:if test="#thread.status == 1">是</s:if><s:else>否</s:else></td>
            <td align="center"><s:property value="formatDate(#thread.createTime)"/></td>
            <td align="center"><s:property value="formatDate(#thread.modifiedTime)"/></td>
            <td align="left" style="padding-left:10px;">
            	<a href='editThread.html?threadId=<s:property value="#thread.id"/>'>编辑</a>
	            |
	            <a href='threadReplyList.html?threadId=<s:property value="#thread.id"/>'>回复管理</a>
	            |
				<s:if test="#thread.sticky == 0">
					<a href="#" id="sticky" onclick="doThreadOper(<s:property value="#thread.id"/>,0,1);">置顶</a>
				</s:if>
				<s:else>
					<a href="#" id="sticky" onclick="doThreadOper(<s:property value="#thread.id"/>,0,0);">取消置顶</a>
				</s:else>
				|
				<s:if test="#thread.digest == 0">
					<a href="#" id="digest" onclick="doThreadOper(<s:property value="#thread.id"/>,1,1);">加精</a>
				</s:if>
				<s:else>
					<a href="#" id="digest" onclick="doThreadOper(<s:property value="#thread.id"/>,1,0);">取消加精</a>
				</s:else>
				|
				<s:if test="#thread.status == 0">
					<a href="#" id="lock" onclick="doThreadOper(<s:property value="#thread.id"/>,2,1);">锁定</a>
				</s:if>
				<s:else>
					<a href="#" id="lock" onclick="doThreadOper(<s:property value="#thread.id"/>,2,0);">取消锁定</a>
				</s:else>
				|
				<s:if test="#thread.deleted == 0">
					<a href="#" id="deleteThread" onclick="doThreadOper(<s:property value="#thread.id"/>,3,1);">删除</a>
				</s:if>
				<s:else>
					<a href="#" id="deleteThread" onclick="doThreadOper(<s:property value="#thread.id"/>,3,0);">删除恢复</a>
				</s:else>
			</td>
        </tr> 
        </s:iterator>     
    </table>
    <%@include file="page.jsp" %>      
    </form>  
</div>
</body>
</html>
<script language="javascript">
	function checkAll(){
		var flag = document.getElementById("checkall").checked;		
   		var elements = document.getElementsByName("threadIds");
   		var len = elements.length;
   		if(len>0){
    		var i=0;
    		for(i=0; i<len; i++){
    			elements[i].checked = flag;
    		}
    	}
	}
	
	function isHaveCheck(){
		var elements = document.getElementsByName("threadIds");
   		var len = elements.length;
   		if(len>0){
    		var i=0;
    		for(i=0; i<len; i++){
    			if(elements[i].checked){
    				return true;
    			}
    		}
    	}
    	
    	return false;
	}
	
	function getCheckedThreadIds(){    
  		var chk_value =[];    
  		$('input[name="threadIds"]:checked').each(function(){    
   			chk_value.push($(this).val());   
   		});    
   		return  chk_value;
 	}
	
</script>
